package com.applink.sell_proof.model;

import java.util.ArrayList;

import com.applink.sell_proof.pojo.GenericAttribute;
import com.applink.sell_proof.share.Parameter;
import com.applink.sell_proof.utilXMLParser.ObjPropInfo;

public class NewRewardClaimDetail {
	private int RewardDetailId;
	private int ProgramID;
	private String ProgramModelNo;
	private String ProgramModelName;
	private String ProgramCategory;
	private int ProgramClaimID;
	private String ProgramInvoiceNo;
	private String ProgramInvoiceDate;
	private String ProgramDistributor;
	private int ProgramQuantity;
	private int ProgramRewardAmount;
	private int ProductCategoryID;
	
	public int getProgramID() {
		return ProgramID;
	}
	public void setProgramID(int programID) {
		ProgramID = programID;
	}
	public String getModelNo() {
		return ProgramModelNo;
	}
	public void setModelNo(String modelNo) {
		ProgramModelNo = modelNo;
	}
	public String getModelName() {
		return ProgramModelName;
	}
	public void setModelName(String modelName) {
		ProgramModelName = modelName;
	}
	public String getProductCategoryName() {
		return ProgramCategory;
	}
	public void setProductCategoryName(String productCategoryName) {
		ProgramCategory = productCategoryName;
	}
	public int getClaimID() {
		return ProgramClaimID;
	}
	public void setClaimID(int claimID) {
		ProgramClaimID = claimID;
	}
	public String getInvoiceNo() {
		return ProgramInvoiceNo;
	}
	public void setInvoiceNo(String invoiceNo) {
		ProgramInvoiceNo = invoiceNo;
	}
	public String getInvoiceDate() {
		return ProgramInvoiceDate;
	}
	public void setInvoiceDate(String invoiceDate) {
		ProgramInvoiceDate = invoiceDate;
	}
	public String getDistributorName() {
		return ProgramDistributor;
	}
	public void setDistributorName(String distributorName) {
		ProgramDistributor = distributorName;
	}
	public int getQuantity() {
		return ProgramQuantity;
	}
	public void setQuantity(int quantity) {
		ProgramQuantity = quantity;
	}
	public int getRewardAmount() {
		return ProgramRewardAmount;
	}
	public void setRewardAmount(int rewardAmount) {
		ProgramRewardAmount = rewardAmount;
	}
	public int getProductCategoryID() {
		return ProductCategoryID;
	}
	public void setProductCategoryID(int productCategoryID) {
		ProductCategoryID = productCategoryID;
	}
	public int getRewardDetailId() {
		return RewardDetailId;
	}
	public void setRewardDetailId(int rewardDetailId) {
		RewardDetailId = rewardDetailId;
	}	
	
	@SuppressWarnings("rawtypes")
	public ArrayList<GenericAttribute> convertIntoGenericAttributes(
			ArrayList<ObjPropInfo> objPropListDetail) {
		
		ArrayList<GenericAttribute> attributeList = new ArrayList<GenericAttribute>();
		
		for(int i=0; i< objPropListDetail.size();i++){
			ObjPropInfo objPropInfo =objPropListDetail.get(i);
    		
    		String name = objPropInfo.getOPID();
    		String dataType = objPropInfo.getDataType();
    		
    		String value = this.getValueByName(name);
    		
    		if(value == ""){
    			value = "0";
    		}
    		if(dataType.compareTo(Parameter.TYPE_INT) == 0) {
    			GenericAttribute<String, Integer> attribute = new GenericAttribute<String, Integer>(name, (int) Long.parseLong(value));
    			attributeList.add(attribute);
    		} else if (dataType.compareTo(Parameter.TYPE_CHAR) == 0){
    			GenericAttribute<String, String> attribute = new GenericAttribute<String, String>(name, String.valueOf(value));
    			attributeList.add(attribute);
    		} else if (dataType.compareTo(Parameter.TYPE_DOUBLE) == 0){
    			GenericAttribute<String, Double> attribute = new GenericAttribute<String, Double>(name, Double.parseDouble(value));           			
    			attributeList.add(attribute);
    		}
    	
		}
		
		return  attributeList;
	}	
	
	

	public String getValueByName(String name){
		
		String value="";
		Object instance;
		try {
			instance = getClass().getDeclaredField(name).get(this);
			value = instance.toString();
		} catch (Exception e) {
			value = "";
		}
		return value;
	}
}
